package tt.love.hw.servlet;

import java.io.IOException;

import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



@SuppressWarnings("serial")
public class ChangeLocaleServlet extends HttpServlet {

	Logger log = LoggerFactory.getLogger(ChangeLocaleServlet.class);

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		process(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		process(req, resp);
	}

	protected void process(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Locale locale;
		if(req.getParameter("code").equals("zh")){
			locale = new Locale("zh", "CN");
		}else{
			locale = new Locale("en", "US");
		}
		String currentpage = req.getParameter("currentpage");
		req.getSession().setAttribute("javax.servlet.jsp.jstl.fmt.locale",
				locale);
		resp.sendRedirect(currentpage);
		
	}

}
